#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QGraphicsDropShadowEffect>





MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    ui->lineEdit->installEventFilter(this);
    ui->lineEdit_2->installEventFilter(this);
    softKeyboard = new SoftKeyboard();
}

MainWindow::~MainWindow()
{
    delete ui;
}


//事件过滤器处理函数
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
    if(event->type()==QEvent::MouseButtonRelease)//事件类型
    {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);//将事件强制转换
        if(mouseEvent->button() == Qt::LeftButton)
        {
            QPoint point = this->pos();
            if(watched == ui->lineEdit)
            {
                softKeyboard->hideInputBufferArea(ui->lineEdit);
                softKeyboard->resize(600,130);


                // 获取lineEdit的全局位置
                QPoint lineEditGlobalPos = ui->lineEdit->mapToGlobal(QPoint(0, 0));
                // 计算softKeyboard的顶部位置
                int newY = lineEditGlobalPos.y() +ui->lineEdit->height();
                // 移动softKeyboard到lineEdit的上方
                softKeyboard->move(point.x() + (this->width() - 600) / 2, newY);
                softKeyboard->setMoveEnabled(false);
                softKeyboard->show();
            }
            if(watched == ui->lineEdit_2)
            {
                connect(softKeyboard,SIGNAL(sendInputBufferAreaText(QString)),this,SLOT(setLineEdit_2Text(QString)));
                softKeyboard->resize(600,130);

                // 获取lineEdit的全局位置
                QPoint lineEditGlobalPos = ui->lineEdit_2->mapToGlobal(QPoint(0, 0));
                // 计算softKeyboard的顶部位置
                int newY = lineEditGlobalPos.y();
                // 移动softKeyboard到lineEdit的上方
                softKeyboard->move(point.x() +(this->width() - 600) / 2, newY);
                softKeyboard->setMoveEnabled(false);
                softKeyboard->show();
            }

        }
    }
    return QMainWindow::eventFilter(watched,event);//返回父类的事件过滤器
}


void MainWindow::setLineEdit_2Text(QString text)
{
    ui->lineEdit_2->setText(text);
}


void MainWindow::on_LoginButton_clicked()
{
    //判断账户密码
    //if(ui->lineEdit->text()=="root" && ui->lineEdit_2->text()=="123456")
   // {
        //进入车牌查询界面
        InfoInquire * Quire = new InfoInquire();
        Quire->show();
        this->close();
   // }
   // else
   // {

      //  QMessageBox::warning(this,"loginerror","账户或密码错误");
   // }
}
